#ifndef QXGAME_GAMECLIENT_H
#define QXGAME_GAMECLIENT_H

#include <string>
#include <atomic>
#include <utility>
#include <unordered_map>
#include <winsock2.h>

#include "Buffer.h"

#pragma comment(lib, "ws2_32.lib")

enum SocketStatus {
    UNKOWN,
    START,
    CREATED,
    CONNECTED,
    DISCONNECT,
    CLOSING,
    CLOSED,
    DISABLE
};

class GameClient {
public:
    GameClient(std::string ip, uint16_t port);
    ~GameClient();
    void Create();
    void Connect();
    void Disconnect();
    void Destroy();
    void LinkThread();

    bool Send(const std::string& data);
    bool Recv();
    void Loop();
    void ParseRecvMsg();
public:
    WSADATA wsaData{};


    Buffer inputBuffer;
    std::atomic<bool> isStop = false;
    std::string ip;
    uint16_t port;
    SOCKET fd = -1;
    SocketStatus status = SocketStatus::UNKOWN;
    std::unordered_map<std::string, std::string> retMap;
};

#endif //QXGAME_GAMECLIENT_H
